package com.topnav.mc.admin.entity.bean;

import com.topnav.mc.admin.entity.DeviceAlarm;
import com.topnav.mc.admin.entity.enums.DeviceAlarmCate;
import com.topnav.mc.position.PositionInfo;
import com.topnav.mc.position.PositionUtil;
import lombok.Data;
import org.springframework.data.redis.core.RedisTemplate;
import com.topnav.mc.uitls.SpringBeanFactory;
/**
 * @Author: kenny
 * @Date: 2023/11/6 14:21
 */
@Data
public class DeviceAlarmBean extends DeviceAlarm {
    private static final long serialVersionUID = 6284805301648853462L;
    private static PositionUtil positionUtil;

    static {positionUtil = SpringBeanFactory.getBean("positionUtil");}

    private String orgCode;
    private String orgName;
    private String shortName;
    private String path;
    private String  userCode;
    private String userName;
    private String  deviceCode;
    private String deviceName;
    private String channelCode;

    private Integer total;
    private String totalCode;
    private String totalName;

    private String alarmCateDesc;

    private Double dLongitude;
    private Double dLatitude;
    private String coordinateSystem;

    private String position;

    public String getAlarmCateDesc(){
        //String desc = DeviceAlarmCate.getDescByCode(this.getAlarmCate());
        return this.getAlarmCate()==null?null:DeviceAlarmCate.getDescByCode(this.getAlarmCate());
    }

    public String getPosition(){
        if (this.getLongitude() == null || this.getLongitude()==0.0){
            if (this.dLongitude != null && this.dLongitude > 0.0){
                return String.valueOf(this.dLongitude) + "," + String.valueOf(this.dLatitude);
            }else{
                if (positionUtil == null) {positionUtil = SpringBeanFactory.getBean("positionUtil");}
                assert positionUtil != null;
                PositionInfo positionInfo = positionUtil.getCurrentPosition(this.deviceCode);
                if (positionInfo != null){
                    return String.valueOf(positionInfo.getLongitude()) + "," + String.valueOf(positionInfo.getLatitude());
                }else{
                    return "0,0";
                }
            }
        }else{
            return String.valueOf(this.getLongitude()) + "," + String.valueOf(this.getLatitude());
        }
        //return "0,0";
    }


/*
    public String getPosition(){
        this.getLongitude()
    }
*/

}
